package com.yuw.producerandconsumer;

public class WarehouseStack {
	
	//属性
	
	//栈对象
	private Product[] whStack;
	//栈顶位置：size表示栈中的元素个数，也就是栈顶的位置，初始位置为0
	private int size = 0;
	
	//栈的容量太小
	private int capacity;

	/**
	 * @param capacity
	 */
	public WarehouseStack(int capacity) {
		
		this.capacity = capacity;
		init();
	}
	
	public WarehouseStack() {
		init();
	}
	
	//行为
	/**
	 *  入栈操作
	 *  
	 * @param obj 入栈的对象
	 */
	public void push(Product obj) {
		//入栈
		whStack[size] = obj;
		//栈顶位置向上移动1位
		size++;
	}
	public Product pop() {
		//栈顶元素指针向下移动一个位置
		size--;
		//取出栈顶元素对象
		Product obj =whStack[size];
		//返回栈顶元素
		return obj;
		
	}
	/**
	 * 栈初始化，默认长度为10
	 * 
	 */
	private void init() {
		if(capacity==0) {
			capacity=10;
		}
		//初始化栈对象
		whStack =new Product[capacity];
	}

	public Product[] getWhStack() {
		return whStack;
	}

	public void setWhStack(Product[] whStack) {
		this.whStack = whStack;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public int getCapacity() {
		return capacity;
	}

	public void setCapacity(int capacity) {
		this.capacity = capacity;
	}
	
	

}
